home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / music_utilities / pt144.dms / pt144.adf / MIDI_Playground-1.03 / SourceCode / wb.c.notUsed < prev   
Text File  |  1993-01-23  |  3KB  |  134 lines

  1. /**************************************************************************
  2. * wb.c:        Workbench interface for MP.
  3. *        Part of MP, the MIDI Playground.
  4. *
  5. * Author:    Daniel Barrett
  6. * Version:    See the file "version.h".
  7. * Copyright:    None!  This program is in the Public Domain.
  8. *        Please share it with others.
  9. ***************************************************************************/
  10.  
  11.     
  12. #include "mp.h"
  13.  
  14.     
  15. #define    TOOL_WINDOW    "WINDOW"    
  16. #define    TOOL_INPUT    "INPUTFORMAT"
  17. #define    TOOL_OUTPUT    "OUTPUTFORMAT"
  18. #define    TOOL_INFILE    "GETFROM"
  19. #define    TOOL_OUTFILE    "PUTINTO"
  20.  
  21.  
  22. struct Library *IconBase = NULL;
  23. #define    ICON_VERSION        33
  24.  
  25.  
  26. BOOL OpenThings(void);
  27. void CloseThings(void);
  28. BOOL ShowTheTools(struct WBArg *wbarg);
  29. BOOL HandleTools(struct WBArg *wbarg, FLAGS theFlags[], char **infile,
  30.         char **outfile);
  31. BOOL CheckIOTool(char *toolValue, int flag, FLAGS theFlags[]);
  32.     
  33. /************************************************************************
  34. * Workbench interface
  35. ************************************************************************/
  36.     
  37. BOOL WorkbenchProgram(char *argv[])
  38. {
  39.     struct WBStartup *argmsg    = (struct WBStartup *)argv;
  40.     struct WBArg *wbarg        = argmsg->sm_ArgList;
  41.     BPTR olddir            = NULL;
  42.     BOOL success            = TRUE;
  43.     FILE *in, *out;
  44.     char *infile, *outfile;
  45.     FLAGS theFlags[NUM_FLAGS];
  46.     
  47.     InitStuff(theFlags, &in, &out, &infile, &outfile);
  48.  
  49.     if (!OpenThings())
  50.         return(FALSE);
  51.  
  52.     if (wbarg->wa_Lock != NULL)
  53.         olddir = CurrentDir(wbarg->wa_Lock);
  54.     else
  55.         olddir = NULL;
  56.  
  57.     if ((success &= HandleTools(wbarg, theFlags, &infile, &outfile))
  58.     &&  (success &= SetupFiles(infile, outfile, &in, &out)))
  59.         (void)MIDIPlayground(theFlags, in, out);
  60.  
  61.     if (olddir != NULL)
  62.         CurrentDir(olddir);
  63.  
  64.     CloseFiles(in, out, infile, outfile);
  65.     return(success);
  66. }
  67.  
  68.     
  69. BOOL OpenThings(void)
  70. {
  71.     return(    (IconBase = OpenLibrary("icon.library", ICON_VERSION))
  72.         ? TRUE
  73.         : FALSE);
  74. }
  75.  
  76.     
  77. void CloseThings(void)
  78. {
  79.     CloseLibrary(IconBase);
  80. }
  81.  
  82.     
  83. BOOL HandleTools(struct WBArg *wbarg, FLAGS theFlags[], char **infile,
  84.         char **outfile)
  85. {
  86.     struct DiskObject *dobj = NULL;
  87.     char **toolarray;
  88.     char *s = NULL;
  89.     BOOL success = TRUE;
  90.  
  91.     if ((wbarg->wa_Name) && (dobj = GetDiskObject(wbarg->wa_Name)))
  92.     {
  93.         toolarray = (char **)dobj->do_ToolTypes;
  94.  
  95.         if (s = (char *)FindToolType(toolarray, TOOL_INPUT))
  96.         {
  97.             success &= CheckIOTool(s, FLAG_ITYPE, theFlags);
  98.             printf("input format=%s\n", s);
  99.         }
  100.  
  101.         if (s = (char *)FindToolType(toolarray, TOOL_OUTPUT))
  102.         {
  103.             success &= CheckIOTool(s, FLAG_OTYPE, theFlags);
  104.             printf("output format=%s\n", s);
  105.         }
  106.  
  107.         if (s = (char *)FindToolType(toolarray, TOOL_INFILE))
  108.         {
  109.             success &= MakeFilename(infile, s);
  110.             printf("input file=%s\n", s);
  111.         }
  112.  
  113.         if (s = (char *)FindToolType(toolarray, TOOL_OUTFILE))
  114.         {
  115.             success &= MakeFilename(outfile, s);
  116.             printf("output file=%s\n", s);
  117.         }
  118.  
  119.         FreeDiskObject(dobj);
  120.         return(success && CheckFlags(theFlags));
  121.     }
  122.     else
  123.         return(FALSE);
  124. }
  125.  
  126.  
  127. /* A tooltype value is legal if it starts with the correct letter; case
  128.  * insensitive. */
  129.     
  130. BOOL CheckIOTool(char *toolValue, int flag, FLAGS theFlags[])
  131. {
  132.     return(IsIOType(theFlags[flag] = tolower(*toolValue)));
  133. }
  134.